package com.sxpi.zixun.controller.questionscategory;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxpi.zixun.bo.QuestionsCategoryBo;
import com.sxpi.zixun.common.enums.ResultStatusEnum;
import com.sxpi.zixun.common.utils.fn.asserts.Vsserts;
import com.sxpi.zixun.controller.BaseController;
import com.sxpi.zixun.pojo.QuestionsCategory;
import com.sxpi.zixun.service.questionscategory.IQuestionsCategoryService;
import com.sxpi.zixun.vo.QuestionsCategoryVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.pug.generator.anno.PugDoc;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 董伟豪
 * @Date: 2022/9/17 10:49
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="文章分类",tabname="kss_question_category")
public class QuestionsCategoryController extends BaseController {

    private final IQuestionsCategoryService questionscategoryService;

    /**
     * 查询文章分类列表信息
     * @return
     */
    @PostMapping("/questionscategory/list")
    @PugDoc(name="查询文章分类列表信息")
    public List<QuestionsCategoryBo> findQuestionsCategoryList() {
        return questionscategoryService.findQuestionsCategoryList();
    }

    /**
     * 查询文章分类列表信息并分页
     * @param questionscategoryVo
     * @return
     */
    @PostMapping("/questionscategory/load")
    @PugDoc(name="查询文章分类列表信息并分页")
    public IPage<QuestionsCategoryBo> findQuestionsCategorys(@RequestBody QuestionsCategoryVo questionscategoryVo) {
        return questionscategoryService.findQuestionsCategoryPage(questionscategoryVo);
    }

    /**
     * 根据文章分类id查询明细信息
     * @param id
     * @return
     */
    @PostMapping("/questionscategory/get/{id}")
    @PugDoc(name="根据文章分类id查询明细信息")
    public QuestionsCategoryBo getQuestionsCategoryById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id, ResultStatusEnum.ID_NOT_EMPTY);
        return questionscategoryService.getQuestionsCategoryById(new Long(id));
    }

    /**
     * 保存和修改文章分类
     * @param questionscategory
     * @return
     */
    @PostMapping("/questionscategory/saveupdate")
    @PugDoc(name="保存和修改文章分类")
    public QuestionsCategoryBo saveupdateQuestionsCategory(@RequestBody QuestionsCategory questionscategory) {
        return questionscategoryService.saveUpdateQuestionsCategory(questionscategory);
    }

    /**
     * 根据文章分类id删除文章分类
     * @param id
     * @return
     */
    @PostMapping("/questionscategory/delete/{id}")
    @PugDoc(name="根据文章分类id删除文章分类")
    public int deleteQuestionsCategoryById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id, ResultStatusEnum.ID_NOT_EMPTY);
        return questionscategoryService.deleteQuestionsCategoryById(new Long(id));
    }

    /**
     * 根据文章分类ids批量删除文章分类
     * @param questionscategoryVo
     * @return
     */
    @PostMapping("/questionscategory/delBatch")
    @PugDoc(name="根据文章分类ids批量删除文章分类")
    public boolean delQuestionsCategory(@RequestBody QuestionsCategoryVo questionscategoryVo) {
        Vsserts.isEmptyEx(questionscategoryVo.getBatchIds(),ResultStatusEnum.ID_NOT_EMPTY);
        return questionscategoryService.delBatchQuestionsCategory(questionscategoryVo.getBatchIds());
    }
}
